package jms.producer;
/**
* Created by WangXJ
* 2018-06-12 10:06
*/

import javax.annotation.Resource;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

public class ProducerServiceImpl implements ProducerService{

	//JMS模板
	@Resource
	JmsTemplate jmsTemplate;
	//目标
	@Resource(name = "topicDestination")
	Destination destination;
	
	public void sendMessage(final String message){
		//使用JmsTemplate发送消息
		jmsTemplate.send(destination, new MessageCreator() {
			public Message createMessage(Session session) throws JMSException {
				TextMessage textMessage = session.createTextMessage(message);
				return textMessage;
			}
		});
		//打印日志
		System.out.println("发送消息成功！  内容为:"+message);

	}

}